cmake_minimum_required(VERSION 3.10)
project(compilerPractice C CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(BISON REQUIRED)
find_package(FLEX REQUIRED)

BISON_TARGET(Parser parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.tab.cpp DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/parser.tab.h)
FLEX_TARGET(Lexer lexer.l ${CMAKE_CURRENT_BINARY_DIR}/lexer.cpp)
ADD_FLEX_BISON_DEPENDENCY(Lexer Parser)

include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_SOURCE_DIR})

add_executable(compiler 
    compiler.cpp
    lexer.cpp
    parser.tab.cpp
    CodeGenerator.cpp
    Optimizer.cpp
    SymbolTable.cpp
    typecheck.cpp
)
add_executable(test_complex test_complex.c)
set_target_properties(test_complex PROPERTIES LINKER_LANGUAGE C)

# 链接库（如有需要）
# target_link_libraries(compiler ...)

# 可选：自定义输出名
set_target_properties(compiler PROPERTIES OUTPUT_NAME "compiler")
set_target_properties(compiler PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
)
